package cn.wolfcode.rbac.domain;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

@Data
// 跟进历史
public class CustomerTraceHistory {

    public static final int TYPE_COMMON = 0;  // 潜在客户
    public static final int TYPE_NORMAL= 1;   // 正式客户

    private Long id;
    // 跟进时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date traceTime;
    // 跟进内容
    private String traceDetails;
    // 跟进方式
    private SystemDictionaryItem traceType;
    // 跟进结果
    private Integer traceResult;
    // 备注
    private String remark;
    // 客户
    private Customer customer;
    // 录入人员
    private Employee inputUser;
    // 录入时间
    private Date inputTime;
    // 跟进类型(0、1)
    // 潜在客户跟进（0、售前）、正式客户跟进（1、售后）
    private Integer type = TYPE_COMMON;

    public String getTypeName() {
        if(type == 1){
            return "正式客户";
        }
        return "潜在客户"; // 0;
    }

    public String getJson(){
        HashMap<String,Object> map = new HashMap();
        map.put("id",id);
        if(customer!= null) {
            map.put("customerId", customer.getId());
            map.put("customerName", customer.getName());
        }
        if(traceTime != null) {
            SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
            map.put("traceTime", date.format(traceTime));
        }
        map.put("traceDetails",traceDetails);
        map.put("traceTypeId",traceType.getId());
        map.put("traceResult",traceResult);
        map.put("type",type);
        return JSON.toJSONString(map);
    }

}